package com.zhj.config.accesslog;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


/**
 * Copyright: Copyright (c) 2020 hantu
 *
 * @ClassName: ApiInterceptor
 * @Description:
 * @version: v1.0.0
 * @author: zhanghaojie
 * @date: 2020/5/14
 */
@Component
@Aspect
public class ApiInterceptor {
    private static Logger logger= LoggerFactory.getLogger(ApiInterceptor.class);

    @Before("@annotation(apiLogAnnotation)")
    public void before(JoinPoint joinPoint, ApiLogAnnotation apiLogAnnotation) throws Exception {
       //得到切入点当前的类的class对象
        Object aThis = joinPoint.getTarget().getClass();
        //得到当前代理类
        Object aThis1 = joinPoint.getThis();
        //获取当前切入方法的参数值
        Object[] args = joinPoint.getArgs();
        if (args[0] instanceof Integer){
            Integer i= (Integer) args[0];
            logger.error(i+"");
        }

        //获取当前执行类型
        String kind = joinPoint.getKind();
        //获取当前切如执行的是那个方法
        Signature signature = joinPoint.getSignature();
        System.out.println(aThis);
    }
}
